﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CommonAlbumInput.ascx.cs" Inherits="admin_webparts_Plug_ins_CommonPage_CommonAlbumInput" %>

<%@ Import Namespace="NTTHAO.Common.BL" %>
<%@ Import Namespace="NTTHAO.Web.BL.CommonPage" %>
<%@ Import Namespace="NTTHAO.CommonWeb" %>

<script type="text/javascript">
NTTHAO.namespace('page');

NTTHAO.page.langText = [];
NTTHAO.page.langText['BLANK_ALBUM_NAME'] = '<%=LanguageUtility.GetLanguageText("BLANK_ALBUM_NAME", Session)%>';
NTTHAO.page.langText['INVALID_NUMBER'] = '<%=LanguageUtility.GetLanguageText("INVALID_INT_NUMBER", Session)%>';
NTTHAO.page.langText['INVALID_IMAGE_FILE'] = '<%=LanguageUtility.GetLanguageText("INVALID_IMAGE_FILE", Session)%>';
var imageEx = '<%=NTTHAO.CommonWeb.Constant.IMAGE_FILE_EXTENTIONS %>'.split(" ");

YAHOO.util.Event.onDOMReady(function(){
    var Event = YAHOO.util.Event,
        Dom = YAHOO.util.Dom,
        dialog,
        calendar;
    Dom.get('<%=txtInsertDate.ClientID %>').readOnly = true;
    var showBtn = Dom.get("btnCal");
    Event.on(showBtn, "click", function() {
        if (!dialog) {
            Event.on(document, "click", function(e) {
                var el = Event.getTarget(e);
                var dialogEl = dialog.element;
                if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {
                    dialog.hide();
                }
            });

            function closeHandler() {
                dialog.hide();
            }

            dialog = new YAHOO.widget.Dialog("container", {
                visible:false,
                context:["show", "tl", "bl"],
                buttons:[ {text:"Hủy", handler: closeHandler, isDefault:true}],
                draggable:false,
                close:true
            });
            dialog.setHeader('Chọn ngày');
            dialog.setBody('<div id="cal"></div>');
            dialog.render(document.body);

            dialog.showEvent.subscribe(function() {
                if (YAHOO.env.ua.ie) {
                    dialog.fireEvent("changeContent");
                }
            });
        }

        if (!calendar) {
            calendar = new YAHOO.widget.Calendar("cal", {
                iframe:false,          // Turn iframe off, since container has iframe support.
                hide_blank_weeks:true, // Enable, to demonstrate how we handle changing height, using changeContent
                locale_months: 'long',
                navigator: true
            });
            calendar.cfg.setProperty("MONTHS_LONG",    ["Tháng 1 /", "Tháng 2 /", "Tháng 3 /", "Tháng 4 /", "Tháng 5 /", "Tháng 6 /", "Tháng 7 /", "Tháng 8 /", "Tháng 9 /", "Tháng 10 /", "Tháng 11 /", "Tháng 12 /"]);
            calendar.cfg.setProperty("WEEKDAYS_SHORT", ["CN", "T.2", "T.3", "T.4", "T.5", "T.6", "T.7"]);
            calendar.render();

            calendar.selectEvent.subscribe(function() {
                if (calendar.getSelectedDates().length > 0) {

                    var selDate = calendar.getSelectedDates()[0];

                    var dStr = selDate.getDate();
                    var mStr = selDate.getMonth() + 1;
                    var yStr = selDate.getFullYear();
    
                    Dom.get("<%=txtInsertDate.ClientID %>").value = (dStr < 10 ? "0" : "") + dStr + "/" + (mStr < 10 ? "0" : "") + mStr + "/" + yStr;
                } else {
                }
                dialog.hide();
            });

            calendar.renderEvent.subscribe(function() {
                dialog.fireEvent("changeContent");
            });
        }

        var inputDateStr = Dom.get("<%=txtInsertDate.ClientID %>").value;
        var d = new Date(
            parseInt(inputDateStr.substr(6, 4), 10), 
            parseInt(inputDateStr.substr(3, 2), 10) - 1, 
            parseInt(inputDateStr.substr(0, 2), 10));
        calendar.cfg.setProperty("selected", inputDateStr.substr(3, 2) + '/' + inputDateStr.substr(0, 2) + '/' + inputDateStr.substr(6, 4));
        calendar.cfg.setProperty("pagedate", d);
        calendar.render();
        
        var x = Dom.getX(showBtn);
        var y = Dom.getY(showBtn);
        var offsetWidth = dialog.element.offsetWidth;
        var offsetHeight = dialog.element.offsetHeight;
        dialog.cfg.setProperty("xy", [x,y-offsetHeight-3]);

        dialog.show();
    });
});

function doSubmit() {
    var oDom = YAHOO.util.Dom;
    //var editor = YAHOO.widget.EditorInfo.getEditorById('<%=_ContentCKEditor.ClientID %>');
    //oDom.get('<%=_ContentCKEditor.ClientID %>').value = editor.getEditorHTML();
    
    var txtAlbumName = document.getElementById("<%=this.txtAlbumName.ClientID %>");
    var txtDefaultWidth = document.getElementById("<%=this.txtDefaultWidth.ClientID %>");
    var txtDefaultHeight = document.getElementById("<%=this.txtDefaultHeight.ClientID %>");
    var txtDefaultMiniWidth = document.getElementById("<%=this.txtDefaultMiniWidth.ClientID %>");
    var txtDefaultMiniHeight = document.getElementById("<%=this.txtDefaultMiniHeight.ClientID %>");
    var fuPresentativeImage = document.getElementById("<%=this.fuPresentativeImage.ClientID %>");
    var fuMiniImage = document.getElementById("<%=this.fuMiniImage.ClientID %>");
    
    var errorMessage = "";

    errorMessage = CheckFieldString("noblank", txtAlbumName, NTTHAO.page.langText['BLANK_ALBUM_NAME']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        txtAlbumName.select();
        txtAlbumName.focus();
        return false;
    }
    
    var imgMiniFileName = Trim(fuMiniImage.value);
    if (!checkFileType(imgMiniFileName, imageEx)) {
        alert(NTTHAO.page.langText['INVALID_IMAGE_FILE']);
        fuMiniImage.focus();
        return false;
    }
    
    var imgFileName = Trim(fuPresentativeImage.value);
    if (!checkFileType(imgFileName, imageEx)) {
        alert(NTTHAO.page.langText['INVALID_IMAGE_FILE']);
        fuPresentativeImage.focus();
        return false;
    }
    <%if (this._Album == null) { %>
    /*
    errorMessage = CheckFieldString("noblank", fuPresentativeImage, NTTHAO.page.langText['INVALID_IMAGE_FILE']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        fuPresentativeImage.select();
        fuPresentativeImage.focus();
        return false;
    }
    */
    <%} %>
    errorMessage = CheckFieldString("noblank", txtDefaultWidth, NTTHAO.page.langText['INVALID_NUMBER']);
    errorMessage += CheckFieldString("integer", txtDefaultWidth, NTTHAO.page.langText['INVALID_NUMBER']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        txtDefaultWidth.select();
        txtDefaultWidth.focus();
        return false;
    }
    errorMessage = CheckFieldString("noblank", txtDefaultHeight, NTTHAO.page.langText['INVALID_NUMBER']);
    errorMessage += CheckFieldString("integer", txtDefaultHeight, NTTHAO.page.langText['INVALID_NUMBER']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        txtDefaultHeight.select();
        txtDefaultHeight.focus();
        return false;
    }
    errorMessage = CheckFieldString("noblank", txtDefaultMiniWidth, NTTHAO.page.langText['INVALID_NUMBER']);
    errorMessage += CheckFieldString("integer", txtDefaultMiniWidth, NTTHAO.page.langText['INVALID_NUMBER']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        txtDefaultMiniWidth.select();
        txtDefaultMiniWidth.focus();
        return false;
    }
    errorMessage = CheckFieldString("noblank", txtDefaultMiniHeight, NTTHAO.page.langText['INVALID_NUMBER']);
    errorMessage += CheckFieldString("integer", txtDefaultMiniHeight, NTTHAO.page.langText['INVALID_NUMBER']);
    if(errorMessage != "")
    {
        alert(errorMessage);
        txtDefaultMiniHeight.select();
        txtDefaultMiniHeight.focus();
        return false;
    }
    oDom.get('<%=txtInsertDate.ClientID %>').readOnly = false;
    return true;
}
</script>
<style type="text/css">
    #spCancel1, #spSave, #spCancel2, #spSave2 {font-size:1.1em; font-weight: bold; }
    #spCancel1 button, #spSave button, #spCancel2 button, #spSave2 button { font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: bold; }
</style>

<div class="tip">
	<h1><%=LanguageUtility.GetLanguageText("IMAGE_ALBUM_INPUT", Session)%></h1>
</div>
<form id="frmInput" runat="server" onsubmit="return doSubmit();">
<p style="text-align: left;">
    <span id="spSave" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?action=view&g=<%=this.Request.QueryString["g"] %>&mnuid=<%=Request.QueryString["mnuid"] %>&time=<%=DateTime.Now.Ticks %>"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
    <script type="text/javascript">
        YAHOO.util.Event.onContentReady("spSave", function () {
            var spSave = new YAHOO.widget.Button("spSave");
        });
        YAHOO.util.Event.onContentReady("spCancel1", function () {
            var spCancel1 = new YAHOO.widget.Button("spCancel1");
            //spCancel1.on("click", function () {location.href='?type=<%=Request.QueryString["type"] %>&name=<%=Request.QueryString["name"] %>';}); 
        });
    </script>
</p>
<table cellspacing="0" cellpadding="3" border="1" class="grid" style="margin: 10px auto;">
    <tr class="odd">
        <td align="right" style="width: 150px;">
            <%=LanguageUtility.GetLanguageText("NAME", Session)%><span style="color: #ff0000;">&nbsp;*</span>
        </td>
        <td>
            <asp:TextBox ID="txtAlbumName" runat="server" Width="400px"></asp:TextBox>
        </td>
    </tr>
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("MINI_IMAGE", Session)%>:
        </td>
        <td>
            <asp:FileUpload ID="fuMiniImage" runat="server" />
            &nbsp;<div style="color: mediumblue; background-color: moccasin; padding: 3px 10px 3px 10px; display: inline;"><%=Constant.IMAGE_FILE_EXTENTIONS%></div>
            <span><%=ConfigValues.GetConfigValue("ALBUM_MINI_IMAGE_SIZE_DEFAULT") %></span>
            <br />
            <div style="margin-top: 5px; height: 24px;"><asp:CheckBox ID="chkResizeMiniImage" runat="server" Checked="true" Text="Resize" onclick="document.getElementById('spanResizeMiniImageSize').style.display = (this.checked ? '' : 'none');"  />
            <span id="spanResizeMiniImageSize"><asp:TextBox ID="txtResizeMiniImageWidth" runat="server" Text="280" Width="50px"></asp:TextBox> x <asp:TextBox ID="txtResizeMiniImageHeight" runat="server" Text="210" Width="50px"></asp:TextBox><b> pixels</b></span></div>
        </td>
    </tr>
    <%if (this._Album != null && this._Album.MiniImage.Trim().Length > 0) { %>
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("CURRENT_IMAGE", Session)%>:
        </td>
        <td>
            <img src="<%=("../" + this._Album.ImagePath + this._Album.MiniImage) %>" style="max-width: 100px; max-height: 100px; border: solid 1px #666; padding: 2px; margin: 2px;" />
            <br />
            <asp:CheckBox ID="chkRemoveMiniImage" Text="Remove" runat="server" />
        </td>
    </tr>
    <%} %>
    <tr class="odd">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("PRESENTATIVE_IMAGE", Session)%><%if (this._Album != null) { %>:<%} else { %><span style="color: #ff0000;display:none;">&nbsp;*</span><%} %>
        </td>
        <td>
            <asp:FileUpload ID="fuPresentativeImage" runat="server" />
            &nbsp;<div style="color: mediumblue; background-color: moccasin; padding: 3px 10px 3px 10px; display: inline;"><%=Constant.IMAGE_FILE_EXTENTIONS%></div>
            <span><%=ConfigValues.GetConfigValue("ALBUM_IMAGE_SIZE_DEFAULT") %></span>
            <br />
            <div style="margin-top: 5px; height: 24px;"><asp:CheckBox ID="chkResizeImage" runat="server" Checked="true" Text="Resize" onclick="document.getElementById('spanResizeImageSize').style.display = (this.checked ? '' : 'none');" />
            <span id="spanResizeImageSize"><asp:TextBox ID="txtResizeImageWidth" runat="server" Text="280" Width="50px"></asp:TextBox> x <asp:TextBox ID="txtResizeImageHeight" runat="server" Text="210" Width="50px"></asp:TextBox><b> pixels</b></span></div>
        </td>
    </tr>
    <%if (this._Album != null && this._Album.Image.Trim().Length > 0) { %>
    <tr class="odd">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("CURRENT_IMAGE", Session)%>:
        </td>
        <td>
            <img src="<%=("../" + this._Album.ImagePath + this._Album.Image) %>" style="max-width: 100px; max-height: 100px; border: solid 1px #666; padding: 2px; margin: 2px;" />
        </td>
    </tr>
    <%} %>
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("DEFAULT_SIZE", Session)%>:</td>
        <td>
            <asp:TextBox ID="txtDefaultWidth" runat="server" Width="50px">800</asp:TextBox> x <asp:TextBox ID="txtDefaultHeight" runat="server" Width="50px">600</asp:TextBox> pixels
        </td>
    </tr>
    <tr class="odd">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("MINI_SIZE", Session)%>:</td>
        <td>
            <asp:TextBox ID="txtDefaultMiniWidth" runat="server" Width="50px">132</asp:TextBox> x <asp:TextBox ID="txtDefaultMiniHeight" runat="server" Width="50px">99</asp:TextBox> pixels
        </td>
    </tr>
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("IMAGE_PATH", Session)%>:</td>
        <td>
            <b><span id="txtImagePath" runat="server">&nbsp;</span></b></td>
    </tr>
    <tr class="odd">
        <td align="right"><%=LanguageUtility.GetLanguageText("ACTIVE", Session)%>:</td>
        <td>
            <asp:CheckBox ID="chkActive" runat="server" Text="Active" Checked="true" /></td>
    </tr>
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("DESCRIPTION", Session)%>:</td>
        <td>
            <asp:TextBox ID="txtDescription" runat="server" Width="600px" Height="100px" TextMode="MultiLine"></asp:TextBox>
        </td>
    </tr>
    <tr class="odd">
        <td align="right"><%=LanguageUtility.GetLanguageText("INSERT_DATE", Session)%>:</td>
        <td>
            <div class="datefield">
                <asp:TextBox ID="txtInsertDate" runat="server" Width="100px" Text="0" CssClass="txtCal"></asp:TextBox>
                <div class="btnCal"><button type="button" id="btnCal" title="Show Calendar"><img src="resources/images/calbtn.gif" width="18" height="18" alt="Calendar"></button></div>
                &nbsp;-&nbsp;<asp:DropDownList ID="cmbInsertHour" runat="server" Width="45"></asp:DropDownList>&nbsp;giờ&nbsp;<asp:DropDownList ID="cmbInsertMin" runat="server" Width="45"></asp:DropDownList>&nbsp;phút
            </div>
        </td>
    </tr>
    <tr class="even">
        <td align="right">
            <%=LanguageUtility.GetLanguageText("CONTENT", Session)%>:</td>
        <td>
            <CKEditor:CKEditorControl ID="_ContentCKEditor" runat="server" BasePath="Resources/js/ckeditor" Font-Names="Verdana" FontNames="Verdana/Verdana, Geneva, sans-serif&#13;&#10;Arial/Arial, Helvetica, sans-serif;&#13;&#10;Comic Sans MS/Comic Sans MS, cursive;&#13;&#10;Courier New/Courier New, Courier, monospace;&#13;&#10;Georgia/Georgia, serif;&#13;&#10;Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;&#13;&#10;Tahoma/Tahoma, Geneva, sans-serif;&#13;&#10;Times New Roman/Times New Roman, Times, serif;&#13;&#10;Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;" Height="450px" Skin="v2" TemplatesFiles="Resources/js/ckeditor/plugins/templates/templates/default.js" ToolbarFull="Source|-|NewPage|-|Templates&#13;&#10;Cut|Copy|Paste|PasteText|PasteFromWord|-|Print|SpellChecker|Scayt&#13;&#10;Undo|Redo|-|Find|Replace|-|SelectAll|RemoveFormat&#13;&#10;Form|Checkbox|Radio|TextField|Textarea|Select|Button|ImageButton|HiddenField&#13;&#10;/&#13;&#10;Bold|Italic|Underline|Strike|-|Subscript|Superscript&#13;&#10;NumberedList|BulletedList|-|Outdent|Indent|Blockquote|CreateDiv&#13;&#10;JustifyLeft|JustifyCenter|JustifyRight|JustifyBlock&#13;&#10;BidiLtr|BidiRtl&#13;&#10;Link|Unlink|Anchor&#13;&#10;Image|SelectImage|MediaEmbed|Flash|Table|HorizontalRule|Smiley|SpecialChar|PageBreak|Iframe&#13;&#10;/&#13;&#10;Styles|Format|Font|FontSize&#13;&#10;TextColor|BGColor&#13;&#10;Maximize|ShowBlocks|-|About" ContentsCss="Resources/js/ckeditor/contents.css"></CKEditor:CKEditorControl>
        </td>
    </tr>
</table>
<p style="text-align: left;">
    <span id="spSave2" class="yui-button yui-link-button yuibtn yuibtn-icon btnsave"><span class="first-child"><asp:Button ID="btnSave2" runat="server" OnClick="btnSave_Click" Text="Save" /></span></span>
    <span id="spCancel2" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?action=view&g=<%=this.Request.QueryString["g"] %>&mnuid=<%=Request.QueryString["mnuid"] %>&time=<%=DateTime.Now.Ticks %>"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
    <script type="text/javascript">
        YAHOO.util.Event.onContentReady("spSave2", function () {
            var spSave2 = new YAHOO.widget.Button("spSave2");
        });
        YAHOO.util.Event.onContentReady("spCancel2", function () {
            var spCancel2 = new YAHOO.widget.Button("spCancel2");
            //spCancel2.on("click", function () {location.href='?type=<%=Request.QueryString["type"] %>&name=<%=Request.QueryString["name"] %>';}); 
        });
    </script>
</p>
</form>
<script type="text/javascript">
//NTTHAO.editor.init('<%=this._ContentCKEditor.ClientID %>', '700px', '350px');
CKEDITOR.on('instanceReady', function(ev) { 
    onWindowResize();
    YAHOO.util.Event.on('<%=_ContentCKEditor.ClientID %>', 'sizeChange', function() {
        onWindowResize();
    });
});

YAHOO.util.Event.onDOMReady(function() {
    //var editor = YAHOO.widget.EditorInfo.getEditorById('<%=_ContentCKEditor.ClientID %>');
    //editor.on('heightChange', function (o, n) {
    //    onWindowResize();
    //});
    
    if(document.getElementById("<%=txtAlbumName.ClientID %>").value == "") {
        document.getElementById("<%=txtAlbumName.ClientID %>").focus();
    }
    
    <%if (_ErrorMessage != string.Empty) { %>
    alert('<%=_ErrorMessage.Replace("\\", "\\\\").Replace("'", "\\'")%>');
    <%} %>
});
</script>